package com.shj.em.biz.report.dto;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Data
public class ReturnRatioDTO {

    private static BigDecimal zero = new BigDecimal(0);

    private static BigDecimal hundred = new BigDecimal(100);

    private List<BigDecimal> shouldAmounts; // 每月应收

    private List<BigDecimal> actualReturn;  // 每月实收

    private List<Integer> targetRatio; // 目标回款率

    private List<BigDecimal> shouldAccumAmounts;

    private List<BigDecimal> actualAccumAmounts;

    private List<BigDecimal> actualReturnRatio;

    private List<BigDecimal> actualAccumReturnRatio;

    // 转化成万元为单位
    public void convert(){
        GrowRatioDTO.convertTo(shouldAmounts);
        GrowRatioDTO.convertTo(actualReturn);
    }

    public void calculate(){
        actualReturnRatio = new ArrayList<>();
        shouldAccumAmounts = new ArrayList<>();
        actualAccumAmounts = new ArrayList<>();
        actualAccumReturnRatio = new ArrayList<>();

        for(int i = 0 ; i < 12; i++){ //12 个月
            if(shouldAmounts.get(i).compareTo(zero) == 0){
                actualReturnRatio.add(zero);
            }else {
                actualReturnRatio.add(actualReturn.get(i).multiply(hundred)
                        .divide(shouldAmounts.get(i), 2, RoundingMode.HALF_UP));
            }
            if(i == 0){
                shouldAccumAmounts.add(shouldAmounts.get(i));
                actualAccumAmounts.add(actualReturn.get(i));
                actualAccumReturnRatio.add(actualReturnRatio.get(i));
            }else{
                shouldAccumAmounts.add(shouldAmounts.get(i).add(shouldAmounts.get(i - 1)));
                actualAccumAmounts.add(actualReturn.get(i).add(actualReturn.get(i-1)));
                actualAccumReturnRatio.add(actualReturnRatio.get(i).add(actualReturnRatio.get(i-1)));
            }
        }
    }

}
